import json
import os
from hashlib import sha256
from typing import  List
from email_validator import validate_email, EmailNotValidError
from fast_captcha import text_captcha
from fastapi import Request, HTTPException, Response, UploadFile
from fastapi.security import OAuth2PasswordRequestForm
from fastapi_pagination.ext.async_sqlalchemy import paginate
from loguru import logger
from sqlalchemy.ext.asyncio import AsyncSession
from app.common.exception import errors
from app.common.exception.agv import AGVError
from app.common.log import log
from app.common.response.response_code import CodeEnum
from app.core.conf import ST
from app.crud import crud_task
from app.database.db_sqlite import async_db_session
from app.models.Task import Task
from app.models.user import User
from app.schemas.task import RSTask,RQTask,StationInfo,DAOCreateTask
from app.schemas.role import RQUpdateRole
from app.utils.generate_string import get_cur_timestamp
from app.crud import crud_user
from app.core.conf import ST
from sio_agv.agv_socket import AGV

async def change_role(obj:RQUpdateRole)->List[RSTask]:
    async with async_db_session.begin() as db:
        await crud_user.update_user_roles_by_id(db,obj.user_id,obj.roles)




async def get_all_role():
    async with async_db_session.begin() as db:
        res = await crud_user.get_users(db)
        return res

